using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;


namespace DataHelper.BLL
{
    public class BK_Ticket
    {
        public int ID { get; set; }
        public int BookingID { get; set; }
        public string FlightNo { get; set; }
        public DateTime StartDate { get; set; }
        public DateTime EndDate { get; set; }
        public int Price { get; set; }
        public int TypeID { get; set; }
        public bool IsDeleted { get; set; }
        public string FromCity { get; set; }
        public string ToCity { get; set; }

        #region BK_TicketSelectAll
        public static List<BK_Ticket> BK_TicketSelectAll(string strSearch="",int top = 1, int bottom = 20, SqlTransaction ConnectionString = null)
        {
            IDataReader dr = DataHelper.DAL.BK_Ticket.BK_TicketSelectAll(strSearch,top,bottom,ConnectionString);
            List<BK_Ticket> BK_TicketList = new List<BK_Ticket>();
            while(dr.Read())
            {
                BK_Ticket myBK_Ticket = new BK_Ticket
                {
                    ID = !dr.IsDBNull(dr.GetOrdinal("ID")) ? (int)dr["ID"] : 0,
                    BookingID = !dr.IsDBNull(dr.GetOrdinal("BookingID")) ? (int)dr["BookingID"] : 0,
                    FlightNo = !dr.IsDBNull(dr.GetOrdinal("FlightNo")) ? (string)dr["FlightNo"] : null,
                    StartDate = !dr.IsDBNull(dr.GetOrdinal("StartDate")) ? (DateTime)dr["StartDate"] : DateTime.Now,
                    EndDate = !dr.IsDBNull(dr.GetOrdinal("EndDate")) ? (DateTime)dr["EndDate"] : DateTime.Now,
                    Price = !dr.IsDBNull(dr.GetOrdinal("Price")) ? (int)dr["Price"] : 0,
                    TypeID = !dr.IsDBNull(dr.GetOrdinal("TypeID")) ? (int)dr["TypeID"] : 0,
                    IsDeleted = !dr.IsDBNull(dr.GetOrdinal("IsDeleted")) ? (bool)dr["IsDeleted"] : false,
                    FromCity = !dr.IsDBNull(dr.GetOrdinal("FromCity")) ? (string)dr["FromCity"] : null,
                    ToCity = !dr.IsDBNull(dr.GetOrdinal("ToCity")) ? (string)dr["ToCity"] : null
                };
                BK_TicketList.Add(myBK_Ticket);
        }
        dr.Close();
        dr.Dispose();
        return BK_TicketList;
        }
        #endregion
        #region BK_TicketSelectRow
        public static BK_Ticket BK_TicketSelectRow(int ID, SqlTransaction ConnectionString = null)
        {
            IDataReader dr = DataHelper.DAL.BK_Ticket.BK_TicketSelectRow(ID, ConnectionString);
            BK_Ticket bk_ticket = null;

            if(dr.Read())
            {
                bk_ticket= new BK_Ticket
                {
                    ID = !dr.IsDBNull(dr.GetOrdinal("ID")) ? (int)dr["ID"] : 0,
                    BookingID = !dr.IsDBNull(dr.GetOrdinal("BookingID")) ? (int)dr["BookingID"] : 0,
                    FlightNo = !dr.IsDBNull(dr.GetOrdinal("FlightNo")) ? (string)dr["FlightNo"] : null,
                    StartDate = !dr.IsDBNull(dr.GetOrdinal("StartDate")) ? (DateTime)dr["StartDate"] : DateTime.Now,
                    EndDate = !dr.IsDBNull(dr.GetOrdinal("EndDate")) ? (DateTime)dr["EndDate"] : DateTime.Now,
                    Price = !dr.IsDBNull(dr.GetOrdinal("Price")) ? (int)dr["Price"] : 0,
                    TypeID = !dr.IsDBNull(dr.GetOrdinal("TypeID")) ? (int)dr["TypeID"] : 0,
                    IsDeleted = !dr.IsDBNull(dr.GetOrdinal("IsDeleted")) ? (bool)dr["IsDeleted"] : false,
                    FromCity = !dr.IsDBNull(dr.GetOrdinal("FromCity")) ? (string)dr["FromCity"] : null,
                    ToCity = !dr.IsDBNull(dr.GetOrdinal("ToCity")) ? (string)dr["ToCity"] : null,

                };
            }
        dr.Close();
        dr.Dispose();
        return bk_ticket;
        }
        #endregion

        #region BK_TicketSelectRowByForeignKey_BookingID
        public static List<BK_Ticket> BK_TicketSelectRowByForeignKey_BookingID(int BookingID, SqlTransaction ConnectionString = null)
        {
            IDataReader dr = DataHelper.DAL.BK_Ticket.BK_TicketSelectRowByForeignKey_BookingID(BookingID,ConnectionString);
            List<BK_Ticket> BK_TicketList = new List<BK_Ticket>();
            while(dr.Read())
            {
                BK_Ticket myBK_Ticket = new BK_Ticket
                {
                    ID = !dr.IsDBNull(dr.GetOrdinal("ID")) ? (int)dr["ID"] : 0,
                    BookingID = !dr.IsDBNull(dr.GetOrdinal("BookingID")) ? (int)dr["BookingID"] : 0,
                    FlightNo = !dr.IsDBNull(dr.GetOrdinal("FlightNo")) ? (string)dr["FlightNo"] : null,
                    StartDate = !dr.IsDBNull(dr.GetOrdinal("StartDate")) ? (DateTime)dr["StartDate"] : DateTime.Now,
                    EndDate = !dr.IsDBNull(dr.GetOrdinal("EndDate")) ? (DateTime)dr["EndDate"] : DateTime.Now,
                    Price = !dr.IsDBNull(dr.GetOrdinal("Price")) ? (int)dr["Price"] : 0,
                    TypeID = !dr.IsDBNull(dr.GetOrdinal("TypeID")) ? (int)dr["TypeID"] : 0,
                    IsDeleted = !dr.IsDBNull(dr.GetOrdinal("IsDeleted")) ? (bool)dr["IsDeleted"] : false,
                    FromCity = !dr.IsDBNull(dr.GetOrdinal("FromCity")) ? (string)dr["FromCity"] : null,
                    ToCity = !dr.IsDBNull(dr.GetOrdinal("ToCity")) ? (string)dr["ToCity"] : null
                };
                BK_TicketList.Add(myBK_Ticket);
        }
        dr.Close();
        dr.Dispose();
        return BK_TicketList;
        }
        #endregion
        #region BK_TicketInsertRow
        public static void BK_TicketInsertRow(int ID, int BookingID, string FlightNo, DateTime StartDate, DateTime EndDate, int Price, int TypeID, bool IsDeleted, string FromCity, string ToCity, SqlTransaction ConnectionString = null)
        {
            DataHelper.DAL.BK_Ticket.BK_TicketInsertRow(ID, BookingID, FlightNo, StartDate, EndDate, Price, TypeID, IsDeleted, FromCity, ToCity, ConnectionString);
        }
        #endregion
        #region BK_TicketUpdateRow
        public static void BK_TicketUpdateRow(int ID, int BookingID, string FlightNo, DateTime StartDate, DateTime EndDate, int Price, int TypeID, bool IsDeleted, string FromCity, string ToCity, SqlTransaction ConnectionString = null)
        {
            DataHelper.DAL.BK_Ticket.BK_TicketUpdateRow(ID, BookingID, FlightNo, StartDate, EndDate, Price, TypeID, IsDeleted, FromCity, ToCity, ConnectionString);
        }
        #endregion
        #region BK_TicketDeleteRow
        public static void BK_TicketDeleteRow(int ID, SqlTransaction ConnectionString = null)
        {
            DataHelper.DAL.BK_Ticket.BK_TicketDeleteRow(ID,ConnectionString);
        }
        #endregion
    }
}
